<?php


namespace App\Dao;


use App\Model\CertificationCompanyApply;

class CertificationCompanyApplyDao extends AbstractDao
{
    public function where(array $where): \Hyperf\Database\Model\Builder
    {
        $builder = CertificationCompanyApply::query();
        foreach ($where as $field => $value) {
            switch ($field) {
                case 'keywords':
                    $builder->whereHas('user', function ($query) use ($value) {
                        $query->where('phone', $value);
                        $query->orWhere('nickname','like', '%'.$value.'%');
                    });
                    break;
                case 'cooperative_ids':
                    $builder->whereIn('cooperative_id', $value);
                    break;
                default:
                    if (is_array($value)) {
                        $builder->where($field, $value[0], $value[1]);
                    } else {
                        $builder->where($field, $value);
                    }
            }
        }
        return $builder;
    }

}